package cn.ycc1.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * @author ycc
 * @date 2024/7/8
 */
public class PersonService implements BeanNameAware, BeanFactoryAware, ApplicationContextAware {
    public PersonService() {
        System.out.println("PersonService被实例化");
    }
    private String name;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        System.out.println("setName被调用");
        this.name = name;
    }
    public void show() {
//        return "name=" + name;
        System.out.println("name=" + name);
    }

    @Override
    public void setBeanName(String arg0) {
        System.out.println("setBeanName被调用 值是：" + arg0);
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("setBeanFactory被调用：beanFactory=" + beanFactory);

//        System.out.println("personService对象：" + beanFactory.getBean("personService"));
//        System.out.println("personService2对象：" + beanFactory.getBean("personService2"));
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
//        System.out.println(applicationContext.getBean("personService"));
        System.out.println("setApplicationContext被调用：" + applicationContext);
    }
}
